home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir39 / emstest3.zip / EMSTEST.CPP < prev    next >
C/C++ Source or Header  |  1994-04-25  |  7KB  |  269 lines

  1. /*
  2.     EMSTEST version 1.1B
  3.     The MINIMALIST Group 4/18/94,4/22/94
  4.     L.Sellers 3
  5.     Written in Borland Turbo C++ 3.00
  6.  
  7.     This version is slightly different than the first, in that it actually
  8.     checks to see if an EMM386 driver is installed before testing it.
  9.     :-) That was a slight oversight, easily corrected in this version.
  10.  
  11.     Note that the test portion of this program will fail when run in the
  12.     integrated Borland C++ development environment because it, by default,
  13.     assigns all expanded memory to it's own use.  If you wish to run it
  14.     while in IDE (for purposes of modifying the code to your own use)
  15.     you must tell your IDE to leave some expanded memory free.
  16.  
  17.     This may differ with different compilers, versions of compilers and
  18.     any upgrades to the C language family.
  19.  
  20.     This program is in the PUBLIC DOMAIN.  All code and information herein
  21.     discussed (except of course references to The MINIMALIST Group and the
  22.     blessed Borland Turbo C++ 3.00) is free for public dispersment and
  23.     usage in whatsoever form desired.
  24. */
  25.  
  26. #include <stdio.h>
  27. #include <dos.h>
  28.  
  29. #define FALSE    0
  30. #define TRUE    !FALSE
  31.  
  32. main()
  33. {
  34.     union REGS regs;
  35.     union SREGS sregs;
  36.     char far *emptr,far *nameptr;
  37.     int n;
  38.     char far *emmstring,far *reference_string;
  39.     unsigned int handle;
  40.  
  41.     puts("\nEMSTEST quick version 1.1B (PUBLIC DOMAIN)");
  42.     puts("The Minimalist Group in-house developments 4/20/94");
  43.     puts("");
  44.  
  45.     /* Is the driver installed? Get the address of the EMS386 driver from
  46.     interrupt 0x67, where it always dwells, and then check to see if the
  47.     tag EMMXXXX0 is there.  If all this is true, there is an expanded memory
  48.     manager active here.  */
  49.     nameptr="EMMXXXX0";
  50.     regs.h.ah=0x35;
  51.     regs.h.al=0x67;
  52.     intdosx(®s,®s,&sregs);
  53.     emptr=(char *)MK_FP(sregs.es,0);
  54.  
  55.     emmstring=emptr+10;
  56.     reference_string=nameptr;
  57.     n=8;
  58.     while(*reference_string && n>0) {
  59.         if(*emmstring!=*reference_string) {
  60.             printf("EMS Driver not detected");
  61.             return 1;
  62.         }
  63.         n--;
  64.         emmstring++;
  65.         reference_string++;
  66.     }
  67.     puts("EMS Driver detected!");
  68.  
  69.  
  70.  
  71.     /* is software operating? ask EMM driver if it is ON and taking requests */
  72.     regs.h.ah=0x40;
  73.     int86(0x67,®s,®s);
  74.  
  75.     switch (regs.h.ah) {
  76.         case 0x00:
  77.             puts("EMS is functional");
  78.             break;
  79.         case 0x80:
  80.             puts("Internal error in EMS software");
  81.             break;
  82.         case 0x81:
  83.             puts("Malfunction in EMS hardware");
  84.             break;
  85.         case 0x84:
  86.             puts("Undefined function");
  87.             break;
  88.         default:
  89.             puts("Undefined ERROR");
  90.     }
  91.  
  92.  
  93.     /* look for page frame segment.  this is the segment in memory where
  94.     all the expanded memory is banked into as needed. Usually 0xe000.
  95.     it is VERY important for the program to remember this address, because
  96.     all the data you use with EMM can only dwell here at this segment! */
  97.     regs.h.ah=0x41;
  98.     int86(0x67,®s,®s);
  99.  
  100.     switch (regs.h.ah) {
  101.         case 0x00:
  102.             printf("Segment of page frame %u (%Xh)\n",regs.x.bx,regs.x.bx);
  103.             break;
  104.         case 0x80:
  105.             puts("Internal error in EMS software");
  106.             break;
  107.         case 0x81:
  108.             puts("Malfunction in EMS hardware");
  109.             break;
  110.         case 0x84:
  111.             puts("Undefined function");
  112.             break;
  113.         default:
  114.             puts("Undefined ERROR");
  115.     }
  116.  
  117.  
  118.     /* get page count.  ask it how many 16k pages this system supports and
  119.     of those how many are actually free to be used by the next program ran. */
  120.     regs.h.ah=0x42;
  121.     int86(0x67,®s,®s);
  122.  
  123.     switch (regs.h.ah) {
  124.         case 0x00:
  125.             printf("Number of unallocated pages %u (%uk)\n",regs.x.bx,regs.x.bx*16);
  126.             printf("Total number of pages in system %u (%uk)\n",regs.x.dx,regs.x.dx*16);
  127.             break;
  128.         case 0x80:
  129.             puts("Internal error in EMS software");
  130.             break;
  131.         case 0x81:
  132.             puts("Malfunction in EMS hardware");
  133.             break;
  134.         case 0x84:
  135.             puts("Undefined function");
  136.             break;
  137.         default:
  138.             puts("Undefined ERROR");
  139.     }
  140.  
  141.  
  142.     /* get EMM version.  the version as of this writting is 4.0 */
  143.     regs.h.ah=0x46;
  144.     int86(0x67,®s,®s);
  145.  
  146.     switch (regs.h.ah) {
  147.         case 0x00:
  148.             printf("EMM version number %u.%u\n",(regs.h.al>>4)&0xf,regs.h.al&0xf);
  149.             break;
  150.         case 0x80:
  151.             puts("Internal error in EMS software");
  152.             break;
  153.         case 0x81:
  154.             puts("Malfunction in EMS hardware");
  155.             break;
  156.         case 0x84:
  157.             puts("Undefined function");
  158.             break;
  159.         default:
  160.             puts("Undefined ERROR");
  161.     }
  162.  
  163.  
  164.     /* get handle count. ask how many groups of expanded memory are being
  165.     currently used. When asking for memory from EMM you specify how many
  166.     blocks of 16K pages you need for each data grouping.  That is, say I
  167.     need 64K to hold a 320x200 256 color background in memory.  I would
  168.     ask for 4 pages (of 16K giving me 64K total) and the expanded memory
  169.     manager would give me a handle number back (say, for example 17).
  170.     From then on out, when ever I need that infomation, I would ask EMM
  171.     to please bring the data at group 17 into memory at the frame segment.
  172.     This is sort of like validated parking where you get a number stub.
  173.     EMM parks the car/data somewhere (don't ask) and when ever you need it
  174.     you show it the stub number and it's brought around for you.
  175.     The following code asks EMM how many of these handles other programs
  176.     (mainly TSRs) are currently using. */
  177.     regs.h.ah=0x4B;
  178.     int86(0x67,®s,®s);
  179.  
  180.     switch (regs.h.ah) {
  181.         case 0x00:
  182.             printf("Number of active EMS handles %u",regs.x.bx);
  183.             if(regs.x.bx==1)
  184.                 puts("  (DEFAULT at startup)");
  185.             else
  186.                 puts("");
  187.             break;
  188.         case 0x80:
  189.             puts("Internal error in EMS software");
  190.             break;
  191.         case 0x81:
  192.             puts("Malfunction in EMS hardware");
  193.             break;
  194.         case 0x84:
  195.             puts("Undefined function");
  196.             break;
  197.         default:
  198.             puts("Undefined ERROR");
  199.     }
  200.  
  201.     /* test. alright. we've gotten this far. let's see if we can allocate
  202.     a block of 64K and then deallocate it without the system complaining. */
  203.     puts("Testing...");
  204.     puts("  Allocating 4 pages (64K)...");
  205.     regs.h.ah=0x43;
  206.     regs.x.bx=4;
  207.     int86(0x67,®s,®s);
  208.     handle=regs.x.dx;
  209.  
  210.     switch (regs.h.ah) {
  211.         case 0x00:
  212.             printf("  Handle is %u\n",handle);
  213.             break;
  214.         case 0x80:
  215.             puts("  Internal error in EMS software");
  216.             break;
  217.         case 0x81:
  218.             puts("  Malfunction in EMS hardware");
  219.             break;
  220.         case 0x84:
  221.             puts("  Undefined function");
  222.             break;
  223.         case 0x85:
  224.             puts("  No more handles available");
  225.             break;
  226.         case 0x87:
  227.             puts("  Allocation request exceeded physical page availablity");
  228.             break;
  229.         case 0x88:
  230.             puts("  Allocation request exceeded logical page availability");
  231.             break;
  232.         case 0x89:
  233.             puts("  Zero pages requested");
  234.             break;
  235.         default:
  236.             puts("  Undefined ERROR");
  237.     }
  238.  
  239.     if(regs.h.ah==0) {
  240.         /* alright. now deallocate it. */
  241.         puts("  Deallocating..");
  242.         regs.h.ah=0x45;
  243.         regs.x.dx=handle;
  244.         int86(0x67,®s,®s);
  245.  
  246.         switch (regs.h.ah) {
  247.         case 0x00:
  248.             puts("  Success!");
  249.             break;
  250.         case 0x80:
  251.             puts("  Internal error in EMS software");
  252.             break;
  253.         case 0x81:
  254.             puts("  Malfunction in EMS hardware");
  255.             break;
  256.         case 0x84:
  257.             puts("  Undefined function");
  258.             break;
  259.         case 0x86:
  260.             puts("  Error in save/restore mapping context");
  261.         default:
  262.             puts("  Undefined ERROR");
  263.         }
  264.     }
  265.  
  266.     return 0;
  267. }
  268.  
  269. /* finis! */